"""
@File    :   app_exception.py
@Time    :   2024/02/22 18:01:01
@Author  :   Qrj
@Email   :   923207736@qq.com
@description   :   自定义异常处理
"""

from fastapi import Request

from src.enums.http_response_code import HttpResponseEnum
from src.exceptions.base import AppException
from src.utils.unified_response import FailApiJSONResponse


async def app_exception_handler(request: Request, exc: AppException):
    """处理自定义异常"""
    # 根据参数来决定是否保存错误堆栈信息
    if exc.echo_exc:
        pass
        # logger.error(exc, exc_info=True)
    return FailApiJSONResponse(
        *exc.args,
        status_code=HttpResponseEnum.SUCCESS.value.code,
        code=exc.code,
        message=exc.msg,
        **exc.kwargs,
    )
